package com.charonmc.utils;

import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;


/**
 * NetworkUtils管理服务端与客户端数据包传递有关方法
 * @author ChuYang
 */

public class NetworkUtils {

    /**
     * 向客户端发送数据包
     * @param playerConnection 客户端连接
     * @param packets 所要发送的数据包
     */
    private static void sendPacket(PlayerConnection playerConnection, Packet<?>... packets) {
        for (Packet<?> packet : packets) {
            playerConnection.sendPacket(packet);
        }
    }

    /**
     * 向客户端发送数据包
     * @param player 户端连接
     * @param packets 所要发送的数据包
     */
    public static void sendPacket(Player player,Packet<?> packets) {
        EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
        sendPacket(entityPlayer.playerConnection,packets);
    }
}